package com.heima.article.lisent;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.article.service.ApArticleService;
import com.heima.common.constants.message.NewsUpOrDownConstants;
import com.heima.model.article.pojos.ApArticleConfig;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 监听文章的上下架
 */
@Component
@Slf4j
public class ArticleUpOrDownListener {
    @Autowired
    ApArticleConfigService apArticleConfigService;

    @RabbitListener(queuesToDeclare = @Queue(NewsUpOrDownConstants.NEWS_UP_FOR_ARTICLE_CONFIG_QUEUE))
    public void listenUp(String articleId){
        apArticleConfigService.update(Wrappers.<ApArticleConfig>lambdaUpdate().set(ApArticleConfig::getIsDown,false)
                .eq(ApArticleConfig::getArticleId,articleId));
    }

    @RabbitListener(queuesToDeclare = @Queue(NewsUpOrDownConstants.NEWS_DOWN_FOR_ARTICLE_CONFIG_QUEUE))
    public void listenDown(String articleId){
        apArticleConfigService.update(Wrappers.<ApArticleConfig>lambdaUpdate().set(ApArticleConfig::getIsDown,true).eq(ApArticleConfig::getArticleId,articleId));
    }
}









